<!-- src/views/case/CaseDetail.vue -->
<script setup>
import { ref, reactive } from 'vue';
import { useCaseStore } from '@/stores/caseStore.js';

const caseStore = useCaseStore();
const dialogVisible = ref(false);

const caseInfo = reactive({
  id: '',
  caseName: '',
  caseTitle: '',
  caseType: '',
  applicantName: '',
  phone: '',
  address: '',
  description: '',
  status: '',
  createTime: ''
});

const show = (caseData) => {
  Object.assign(caseInfo, caseData);
  caseInfo.id = caseData.id;
  dialogVisible.value = true;
};

const close = () => {
  dialogVisible.value = false;
};

// 对外暴露show方法
defineExpose({
  show
});

const formatStatus = (status) => {
  const statusMap = {
    'IN_PROGRESS':'未进行',
    'PENDING':'进行中',
    'CLOSED':'已完成'
  }
  return statusMap[status] || status;
}

const formatCaseType = (caseType) => {
  return caseType === 1 ? '民事案件' : '刑事案件';
}
</script>

<template>
  <el-dialog
      title="案件详情"
      v-model="dialogVisible"
      width="50%"
  >
    <el-form :model="caseInfo" label-width="120px">
      <el-form-item label="案件名称">
        <el-input v-model="caseInfo.caseTitle" readonly />
      </el-form-item>

      <el-form-item label="申请人">
        <el-input v-model="caseInfo.applicantName" readonly />
      </el-form-item>

      <el-form-item label="联系电话">
        <el-input v-model="caseInfo.phone" readonly />
      </el-form-item>

      <el-form-item label="案件类型">
        <el-input :value="formatCaseType(caseInfo.caseType)" readonly />
      </el-form-item>

      <el-form-item label="状态">
        <el-input :value="formatStatus(caseInfo.status)" readonly />
      </el-form-item>

      <el-form-item label="申请时间">
        <el-input v-model="caseInfo.createTime" readonly />
      </el-form-item>

      <el-form-item label="案件描述">
        <el-input v-model="caseInfo.description" type="textarea" readonly />
      </el-form-item>

      <el-form-item>
        <el-button @click="close">关闭</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped>
</style>
